#include "grflib_stdafx.h"
#include "../include/grflibEffects.h"
#include "../include/D3D10Engine.h"
#include "../include/Material.h"
#include "../include/Texture.h"

namespace grflib { namespace engine { namespace aux {

CSkyBoxEffect::CSkyBoxEffect()
{
	m_filename = _T("grflibSkybox.fxo");
	AddTechnique("Render");
	AddShaderVariable("World", CEffect::SVUSE_MATRIX);
	AddShaderVariable("View", CEffect::SVUSE_MATRIX);
	AddShaderVariable("Projection", CEffect::SVUSE_MATRIX);
	AddShaderVariable("EnvMap", CEffect::SVUSE_SHADER_RESOURCE);
}

CSkyBoxEffect::~CSkyBoxEffect()
{
}

using namespace engine::core;
HRESULT CSkyBoxEffect::SetShaderVariables(boost::shared_ptr<CMaterial> &pMaterial, const std::string &strTechnique)
{
	HRESULT hr;
	
    CMaterial::texture_slot_type::iterator iter;
    if ((iter = pMaterial->textureSlots.find("cube")) != pMaterial->textureSlots.end())
    {
        boost::shared_ptr<CTextureCube> &pTex = boost::dynamic_pointer_cast<CTextureCube>( _ResrcMan.FindObj(iter->second) );
        if (pTex)
        {
            ID3D10EffectShaderResourceVariable *pSRVar;
            pSRVar = GetShaderVariable("EnvMap")->AsShaderResource();
            V_RETURN( pSRVar->SetResource(pTex->GetShaderResourceView()) );
        }
    }

	return S_OK;
}

}}} // namespaces